<?php
App::uses('AppController', 'Controller');
/**
 * Articles Controller
 *
 * @property Article $Article
 * @property PaginatorComponent $Paginator
 */
class ChocolatesController extends AppController 
{
    var $uses = array('ProductCategory', 'Article');
/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator','Cookie','Session');
	public $paginate = array(
        'conditions' => array('article_category_id' => 2),
        'limit' => 5,
        'order' => array(
            'Article.created_date' => 'DESC'
        )
    );

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view() {
        $id = 26;
		if (!$this->Article->exists($id)) {
			throw new NotFoundException(__('Invalid article'));
		}
        $this->ProductCategory->recursive = 0;
		$categoryDetail = $this->ProductCategory->findById(46);
		$this->set('categoryDetail', $categoryDetail);
        
		$options = array(
            'conditions' => array('ProductCategory.product_brand_id' => $categoryDetail['ProductCategory']['product_brand_id']),
            'order' => 'category_name_en ASC'
        );
        $this->set('categoryList', $this->ProductCategory->find('all', $options));
        
		$options = array('conditions' => array('Article.' . $this->Article->primaryKey => $id));
		$this->set('article', $this->Article->find('first', $options));
	}
    
    public function send_us_your_order()
    {
        if($this->request->isPost()){
            $arrayData = $this->request->data;
            $data = array();
            foreach($arrayData as $row) {
                $data[$row['name']] = $row['value'];
            }

            App::uses('CakeEmail', 'Network/Email');
            $email = new CakeEmail('smtp');
            $email->to(array('ngocha@unitedvision.com.vn', 'thuydinh@chocolategraphics.com.vn'));
            $email->cc($data['email']);
            $email->viewVars(array('data' => $data));
            $email->template('logo_process');
            $email->subject(__('Logo Process Order',true));
            if($email->send()) {
                echo 1;exit;
            } else {
                echo 0;exit;
            }
        }
        
        echo 0;
        exit;
    }
}
